from rest_framework.views import APIView
# from bus.settings import alipay
from bus import settings
from user.models import *
from rest_framework.response import Response
import json


class Ali(APIView):
    def post(self, request):
        subject = "余额充值"
        # 电脑网站支付，需要跳转到https://openapi.alipay.com/gateway.do? + order_string
        order_string = alipay.api_alipay_trade_page_pay(
            # 订单号
            out_trade_no="唯一不重复字符串",
            # 金额
            total_amount="金额",
            subject='subject',
            # 回调地址
            return_url=settings.RETURN_URL,
            # notify_url="http://localhost:8000/pay/ali_back/"  # 可选, 不填则使用默认notify url
        )

        pay_url = 'https://openapi.alipaydev.com/gateway.do?' + order_string
        return Response({'data': {'pay_url': pay_url, 'msg': 'OK', "code": 200}})


class AliBack(APIView):
    def get(self, request):
        data = request.data
        data.pop("sign")
        print(data)
        return Response({"code": 200, "msg": 'ok'})
